
import * as actionTypes from '../actionTypes'

// 获得所有商品列表
export function getAllProducts() {
  return {
    type: actionTypes.GET_ALL_PRODUCTS
  }
}

// 获取商品列表
export function receiveProducts(products) {
  return {
    type: actionTypes.RECEIVE_PRODUCTS,
    products: products
  }
}

// 加入购物车
export function addToCart(productId) {
  return {
    type: actionTypes.ADD_TO_CART,
    productId
  }
}

// 移除购物车
export function removeFromCart(productId) {
  return {
    type: actionTypes.REMOVE_FROM_CART,
    productId,
  }
}

// 发起结算请求
export function checkout() {
  return {
    type: actionTypes.CHECKOUT_REQUEST
  }
}

// 结算请求成功
export function checkoutSuccess(cart) {
  return {
    type: actionTypes.CHECKOUT_SUCCESS,
    cart
  }
}

// 结算失败
export function checkoutFailure(message) {
  return {
    type: actionTypes.CHECKOUT_FAILURE,
    message
  }
}